package hb.software.register.entitygenerator;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import hb.software.register.domain.Register;
import hb.software.register.service.RegisterManager;
import hb.software.service.GenericManagerTestCase;

/** 
 * @ClassName: RegisterEntityGenerator 
 * @Description: TODO
 * @author YangXinliang
 * @date May 29, 2020 1:44:55 PM 
 *  
 */
@ContextConfiguration(locations = { "classpath:applicationContextTest-resources.xml",
		"classpath:applicationContext-dao.xml", "classpath:applicationContext-service.xml" })
public class RegisterEntityGenerator extends AbstractJUnit4SpringContextTests {

	List<Register> registerList;

	RegisterManager registerManager;

	@Autowired
	public void setworkerMessageManager(RegisterManager registerManager) {
		this.registerManager = registerManager;
	}

	@Before
	public void setUp() throws Exception {
		this.registerList = new ArrayList<Register>();
		InputStream input = GenericManagerTestCase.class.getResourceAsStream("/workermanagerment_register_software.xlsx");
		@SuppressWarnings("resource")
		XSSFWorkbook wb = new XSSFWorkbook(input);
		XSSFSheet sheet = wb.getSheetAt(0);
		for (int i = 1; i <= sheet.getLastRowNum(); i++) {
			Row row = sheet.getRow(i);
			Register s = new Register();
			for (int j = 0; j < row.getLastCellNum(); j++) {
				Cell cell = row.getCell(j);
				if (cell != null) {
					cell.setCellType(CellType.STRING);
					String value = row.getCell(j).getStringCellValue().trim();
					if (j == 1)
						s.setUsername(value);
					if (j == 2)
						s.setPassword(value);
					
					
						}
				}
			this.registerList.add(s);
			}
	
			
		}


	
	@Test
	public void test() {
		this.registerManager.deleteAll();
		this.registerManager.save(this.registerList);
		Iterable<Register> result = this.registerManager.findAll();
		if (logger.isInfoEnabled()) {
			logger.info("test() - List<workerMessage> result=" + result); //$NON-NLS-1$
		}
	}

}
